using System;
using System.Drawing;
using Spread.Common.DataStore;
using FarPoint.Win.Spread;

namespace Spread.Filtering.Features
{
    public partial class FilterGadget : Spread.Common.Features.Sample.BaseSampleControl
    {
        private AccessDataSource _dataSource;

        public FilterGadget()
        {
            InitializeComponent();
            Name = "Filter Gadget";
            _dataSource = new DataService().AccessDataSource;

            InitSpreadSheet(fpSpread.ActiveSheet);
        }

        private void InitSpreadSheet(SheetView sheet)
        {
            sheet.DataSource = _dataSource.GetDataFrom("fpWine.mdb", "select OrderID, CustomerID," +
                "SalesPerson, OrderDate, ShippedDate, Freight from Orders");
            
            sheet.Columns[2].Width = 120;
            sheet.Columns[3, 4].Width = 80;
            sheet.Columns[5].Width = 70;

            sheet.SetMultipleRowHeights(0, sheet.RowCount, 20);

            Random random = new Random();
            var colors = Enum.GetValues(typeof(KnownColor));
            for (int row = random.Next(0, 4); row < sheet.RowCount; row += random.Next(1, 5))
            {
                sheet.Cells[row, 1].BackColor = Color.FromKnownColor((KnownColor)(colors.GetValue(
                    random.Next(27, colors.GetUpperBound(0) + 1))));
            }

            for (int col = 0; col < sheet.ColumnCount; ++col)
            {
                sheet.Columns[col].AllowAutoFilter = true;
                sheet.Columns[col].Width = sheet.GetPreferredColumnWidth(col, PreferredSizeColumnOptions.IncludeAll);
            }
            sheet.AutoFilterMode = AutoFilterMode.FilterGadget;
        }
    }
}


//
//FilterGadget.Designer.cs
//


namespace Spread.Filtering.Features
{
    partial class FilterGadget
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.fpSpread = new FarPoint.Win.Spread.FpSpread();
            this.fpSpread_Sheet1 = new FarPoint.Win.Spread.SheetView();
            this.pnlMain.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread_Sheet1)).BeginInit();
            this.SuspendLayout();
            // 
            // pnlMain
            // 
            this.pnlMain.Controls.Add(this.fpSpread);
            // 
            // fpSpread
            // 
            this.fpSpread.Dock = System.Windows.Forms.DockStyle.Fill;
            this.fpSpread.Location = new System.Drawing.Point(0, 0);
            this.fpSpread.Name = "fpSpread";
            this.fpSpread.Sheets.AddRange(new FarPoint.Win.Spread.SheetView[] {
            this.fpSpread_Sheet1});
            this.fpSpread.Size = new System.Drawing.Size(477, 487);
            this.fpSpread.Skin = FarPoint.Win.Spread.DefaultSpreadSkins.Office2016White;
            this.fpSpread.StatusBarVisible = true;
            this.fpSpread.TabIndex = 0;
            // 
            // fpSpread_Sheet1
            // 
            this.fpSpread_Sheet1.Reset();
            this.fpSpread_Sheet1.SheetName = "Sheet1";
            // Formulas and custom names must be loaded with R1C1 reference style
            this.fpSpread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1;
            this.fpSpread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1;
            // 
            // SpreadFilterGadget
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Name = "SpreadFilterGadget";
            this.pnlMain.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread_Sheet1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private FarPoint.Win.Spread.FpSpread fpSpread;
        private FarPoint.Win.Spread.SheetView fpSpread_Sheet1;
    }
}
